<!--考生申请-->
<template>
  <div>
    <el-form :inline="true" :model="requestData" style="width: 100%;margin-bottom: -10px;margin-top: -10px;" label-width="80px">
      <el-form-item label="考场名称">
        <el-input size="mini" v-model="requestData.map.tr_name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="success" icon="el-icon-search" @click="searchInfo">查询</el-button>
        <el-button size="mini" icon="el-icon-search" @click="clearSearchInfo">重置</el-button>
        <el-button size="mini" type="danger" icon="el-icon-delete" @click="deleteInfoList">删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      @selection-change="handleSelectionChange">
      <el-table-column
        align="center"
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        align="center"
        prop="user_id"
        label="考生id"
        minWidth="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="user_name"
        label="用户名"
        minWidth="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="user_nick_name"
        label="昵称"
        minWidth="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="tr_name"
        label="考场"
        minWidth="120">
      </el-table-column>
      <el-table-column
        label="操作"
        minWidth="180"
        align="center">
        <template slot-scope="scope">
          <el-button size="mini"  type="success" @click="insertTestRoom(scope.$index, scope.row)">同意</el-button>
          <el-button type="danger" icon="el-icon-delete"  size="mini" @click="deleteInfo(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[10, 20, 30, 40,50]"
      :page-size="pageInfo.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
  </div>
</template>
<script>
  import{selectUnRoomUser,allowUser,deleteAllowUser,selectTestRoom} from "@/api/invigilate";
  export default{
    created(){
        this.getTableData();
    },
    data(){
      return {
        tableData:[],
        selectList:[],

        pageInfo:{
          page:1,//页数
          size:10, //页面大小
          total:0 //页总数
        },
        requestData:{
          pageSize:10,
          pageNum:1,
          map:{
            tr_name:''
          }
        }
      }
    },
    methods:{
        getTableData(){
          this.tableData = [];
          selectUnRoomUser(this.requestData).then(res=>{
              if(res.code == 200){
                  let dataList = res.data.data;
                  for(let obj of dataList){
                      for(let obj1 of obj.roomUserList){
                          let s = {tr_name:obj.tr_name};
                          s.ru_id = obj1.ru_id;
                          s.user_name = obj1.user.user_name;
                          s.user_nick_name = obj1.user.user_nick_name;
                          s.user_id = obj1.user.user_id;
                          this.tableData.push(s);
                      }
                  }
              }
          })
        },

      searchInfo(){
            this.getTableData();
      },

      clearSearchInfo(){
        this.requestData.map.tr_name = "";
        this.getTableData();
      },

      deleteInfoList(){
        if(this.selectList == null || this.selectList.length <= 0){
          this.$message({
            type: 'warning',
            message: '请至少选择一行要删除的数据'
          });
        }else{
          this.$confirm('此操作将删除该条数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            deleteAllowUser(this.selectList).then(res=>{
              if(res.code == 200){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
                this.selectList = [];
                this.getTableData();
              }
            })
          }).catch(() => {

          });
        }
      },

        //同意申请
       insertTestRoom(index,row){
         allowUser({ru_id:row.ru_id}).then(res=>{
             if(res.code == 200){
               this.$message({
                 message: '同意完成',
                 type: 'success'
               });
               this.getTableData();
             }
         })
       },

      //删除申请信息
      deleteInfo(index,row){
        let deleteArray = [{ru_id:row.ru_id}];
        this.$confirm('此操作将删除该条数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteAllowUser(deleteArray).then(res=>{
            if(res.code == 200){
              this.$message({
                type: 'success',
                message: '删除成功'
              });
              this.getTableData();
            }else{
              this.$message({
                type: 'error',
                message: '删除失败'
              });
            }
          });
        }).catch(() => {

        });
      },

      //复选框选择的数据
      handleSelectionChange(val){
        this.selectList = val;
      },
      //每页的条数发生改变时调用
      handleSizeChange(size){
        this.requestData.pageSize = size;
        this.pageInfo.size = size;
        this.getDataList();
      },

      //页数发生改变时调用
      handleCurrentChange(page){
        this.requestData.pageNum = page;
        this.pageInfo.page = page;
        this.getDataList();
      },
    }
  }
</script>
